<template>
  <view class="menu-container">
    <view class="menu-grid">
      <view
        v-for="(item, index) in educationList"
        :key="index"
        class="menu-item"
        @click="handleClick(item)"
      >
        <view class="icon-wrapper">
          <img :src="item.linkIcon" :alt="item.linkName" class="custom-icon" />
        </view>
        <view class="menu-text">{{ item.linkName }}</view>
      </view>
    </view>
    <van-empty v-if="!educationList.length" description="暂无数据" />
  </view>
</template>

<script>
import { tbExternalLinkList } from '../../api/tbExternalLink'
import articleItem from './components/articleItem.vue'
import { toMiniProgram } from '../../utils/utils'
export default {
  name: 'wx_pages_fzbz_businessPro',
  components: { articleItem },
  data() {
    return {
      menuList: [
        {
          name: '居住证换领',
          icon: 'jzzhl.png',
          path: '',
        },
        {
          name: '居住证补签',
          icon: 'jzzbq.png',
          path: '',
        },
        {
          name: '居住证续签',
          icon: 'jzzxq.png',
          path: '',
        },
        {
          name: '居住证换领',
          icon: 'jzzhl_1.png',
          path: '',
        },
      ],
      educationList: [],
    }
  },
  methods: {
    handleClick(row) {
      if (row.linkUrl.indexOf('@@') >= 0) {
        const [appid, path] = row.linkUrl.split('@@')
        toMiniProgram(appid, path)
      } else {
        if (row.linkUrl.startsWith('/pages')) {
          this.$toPage(row.linkUrl)
        } else {
          this.$toPage(
            `/pages/share/qrcode?qrcode=${row.qrcode}&link=${row.linkUrl}`
          )
        }
      }
    },
    async search() {
      this.$showLoading('查询中...')
      let res = await tbExternalLinkList({ linkType: '3', linkSubType: '8' })
      this.$hideLoading()
      if (res.data && res.data.length > 0) {
        this.educationList = res.data.map((item) => {
          const linkUrl = item.linkUrl
          const [appId, path, ghId] = (linkUrl || '').split('@@')
          const params = {
            ...item,
            appId,
            ghId,
            path,
          }
          return params
        })
      } else {
        this.educationList = []
      }
    },
  },
  mounted() {
    console.log(this)
  },
  onLoad() {
    this.search()
  },
}
</script>

<style scoped>
.menu-container {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin: 0 auto;
}

.menu-item {
  background-color: #f5f9f7;
  border-radius: 8px;
  padding: 16px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.menu-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.15);
}

.icon-wrapper {
  width: 50px;
  height: 50px;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.custom-icon {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.menu-text {
  color: #333;
  font-size: 16px;
  margin-top: 8px;
}
</style>